"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/7/10 10:57
@Description : 

"""
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

# 设置浏览器参数
options = webdriver.ChromeOptions()
options.add_experimental_option('detach', True)
chrome = webdriver.Firefox()
# 打开目标地址
chrome.get('https://search.dangdang.com/?key=python&act=input&page_index=1')
chrome.maximize_window()
time.sleep(2)
while True:
    # 获取屏幕总高度
    height = chrome.execute_script("return document.body.scrollHeight")
    # 设置移动步长
    step = 200
    for i in range(0, height, step):
        # 实现鼠标的滚动  浏览网页    参数1 x  参数2  y 500px
        chrome.execute_script(f'window.scrollTo(0, {i})')
        time.sleep(0.2)
    time.sleep(2)
    # 获取下一页
    chrome.find_element(By.CSS_SELECTOR, 'li[class="next"]').click()

